package com.company.card_service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.company.card_service.model.CompanyImage;
import com.company.card_service.mapper.CompanyImageMapper;
import com.company.card_service.service.CompanyImageService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.company.card_service.vo.CompanyImageVo;
import com.company.card_service.vo.Result;
import com.company.card_service.vo.ResultCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 赵志浩
 * @since 2022-09-15 04:19:37
 */
@Service
public class CompanyImageServiceImpl extends ServiceImpl<CompanyImageMapper, CompanyImage> implements CompanyImageService {

    @Autowired
    private CompanyImageMapper companyImageMapper;

    @Override
    public Result listCompanyImgs(int cid) {
//        QueryWrapper<CompanyImageVo> wrapper = new QueryWrapper<CompanyImageVo>()
//                .eq("is_deleted",0)
//                .orderByDesc("update_time")
//                .last("limit 0,3");
//        List<CompanyImage> companyImages = companyImageMapper.selectList(wrapper);
        List<CompanyImageVo> companyImageVos = companyImageMapper.selectCompanyImageListById(cid);
        if (companyImageVos.size() == 0){
            return Result.fail(ResultCodeEnum.FAIL.getCode(),ResultCodeEnum.FAIL.getMessage());
        }else {
            return Result.success(ResultCodeEnum.SUCCESS.getCode(),ResultCodeEnum.SUCCESS.getMessage(),companyImageVos);
        }
    }
}
